package com.qf.mvc2203.ex;

import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 统一异常处理器
 * 注意：要把 自定义的统一异常处理器放入IOC容器中才可以生效
 */
public class MyExResolver implements HandlerExceptionResolver {
    @Override
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {

        ex.printStackTrace();

        final ModelAndView mv = new ModelAndView();

        if (ex instanceof UserException){
            mv.setViewName("redirect:/error/error02.html");

        }else {
            mv.setViewName("redirect:/error/error01.html");
        }

        return mv;
    }
}
